<template>
  <entity-view
    :operator-type="operatorType"
    :model="beanInfo"
    @submit="submit"
    :rules="rules"
    ref="form"
  >
    <div class="sub-content-flex">
      <form-item
        label="机构标识"
        v-model="beanInfo.instId"
        prop="instId"
        disabled
      ></form-item>
      <form-item
        label="变更数据"
        v-model="beanInfo.paramKey"
        prop="paramkey"
        disabled
      ></form-item>
      <form-item
        label="原机构"
        v-model="beanInfo.signinstid"
        prop="signinstid"
      ></form-item>
      <form-item
        label="并入机构"
        v-model="beanInfo.newsigninstid"
        prop="newsigninstid"
      ></form-item>
    </div>
  </entity-view>
</template>
<script>
import EntityView from "../../../../components/common/entityView/EntityView.vue";
import FormItem from "../../../../components/common/entityView/FormItem.vue";

export default {
  name: "OrgAbolishAndMergeOperation",
  components: {
    EntityView,
    FormItem,
  },
  props: {
    query: Object,
  },
  data: function () {
    return {
      operatorType: "edit",
      beanInfo: {
        instId: "",
        paramKey: "",
        paramValue: "",
        signinstid: "",
        newsigninstid: ""
      },
      rules: {
        instId: [{ required: true, message: "必填", trigger: "blur" }],
        paramKey: [{ required: true, message: "必填", trigger: "blur" }],
        signinstid: [{ required: true, message: "必填", trigger: "blur" }],
        newsigninstid: [{ required: true, message: "必填", trigger: "blur" }],
      },
      loading: false,
    };
  },

  methods: {
    async submit() {
      let res;
      switch (this.operatorType) {
        case "edit":
          res = await this.edit();
          break;
        default:
          break;
      }
      return res;
    },
    async edit() {
        const res = await this.$refs.form.validate();
        if (res) {
          const params = this.beanInfo;
          const res = await this.$post(
            "/admin/igas/OrgAbolishAndMerge/edit",
            params
          );
          if (res.data.code === "100000") {
            this.$message.success(res.data.message);
            return true;
          } else {
            this.$message.error(res.data.message);
            return false;
          }
        }
    },
    resetFields() {
      return this.$refs.form.resetFields();
    },
    setOperatorType(type) {
      this.operatorType = type;
    },

    setBeanInfo({...beanInfo}) {
      this.beanInfo = beanInfo;
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../../../../static/less/Common";
.subtitle {
  width: 100%;
  font-size: 18px;
  margin-bottom: 10px;
}
.sub-content-flex {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}
.sub-content-block {
  display: block;
  flex-wrap: wrap;
  width: 100%;
}
</style>
